<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body onload="fun()" background="img/Chrysanthemum.jpg">
		请选择网页背景:<select id="op" onchange="changeImg()"></select>
		<script>
			var images = [];
			function fun(){
				var xhr = new XMLHttpRequest();
				//xhr.open("GET","image.xml",true);//文本写法
				xhr.open("GET","image2.xml",true);//属性写法
				xhr.send();
				xhr.onreadystatechange = function(){
					if (xhr.readyState==4 && xhr.status==200) {
						var data  = xhr.responseXML; //服务器返回的XML将保存在responseXML属性中
						images = data.getElementsByTagName("image");
						var op = document.getElementById('op');
						for (var i=0;i<images.length;i++) {
							//op.options[i] = new Option(images[i].getElementsByTagName("name")[0].innerHTML)
							op.options[i] = new Option(images[i].getAttribute("name"))
						}
					}
				}
			}
			function changeImg(){
				var op = document.getElementById('op');
				//var url = images[op.selectedIndex].getElementsByTagName("url")[0].innerHTML;
				var url = images[op.selectedIndex].getAttribute("url");
				document.body.style.background = "url("+url+")";
			}
		</script>
	</body>
</html>
